<template>
    <el-dialog width="550" v-model="showDialog" :close-on-click-modal="false" :modal-append-to-body="false"
        :close-on-press-escape="false">
        <!-- <template #header>
            <span>备注</span>
        </template> -->
        <div class="container">
            <el-form ref="refRemark" :model="queryParams" :inline="true" label-width="150px" :rules="rules">
                <el-form-item label="最后处理时间" prop="lastHandleTime" v-if="currentType == 'clsj'">
                    <el-date-picker v-model="queryParams.lastHandleTime" type="date" placeholder="请选择时间"
                        :shortcuts="shortcuts" format="YYYY-MM-DD" value-format="YYYY-MM-DD" size="small" />
                </el-form-item>
                <el-form-item label="超频原因与处理进度" prop="overFrequencyCause" v-else>
                    <el-input type="textarea" v-model="queryParams.overFrequencyCause" style="width: 240px"></el-input>
                </el-form-item>
            </el-form>
        </div>
        <template #footer>
            <span class="dialog-footer">
                <slot name="extendBtn"></slot>
                <el-button type="primary" @click="approvelSubmit()">提交</el-button>
                <el-button @click="showDialog = false">关闭</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup>
// core
import { ref } from "vue";

// import { approveSubmit } from "@/api/biz/exportApi";
import { ElMessage } from 'element-plus'
import { addNotes } from '@/api/biz/maintenance';

const emit = defineEmits(['reflash'])

const { proxy } = getCurrentInstance();

const shortcuts = [
    {
        text: "Today",
        value: new Date(),
    },
    {
        text: "Yesterday",
        value: () => {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            return date;
        },
    },
    {
        text: "A week ago",
        value: () => {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            return date;
        },
    },
];

const rules = {
    // remark: [{ required: true, trigger: "blur", message: "请输入" }],
    // lastHandleTime: [{ required: true, trigger: "blur", message: "请输入" }],
};

const queryParams = ref({})
const refRemark = ref(null)
let currentType = ref('')

const showDialog = ref(false);

const approvelSubmit = () => {
    proxy.$refs["refRemark"].validate(valid => {
        if (valid) {
            // console.log(queryParams.value)
            addNotes(queryParams.value).then(res => {
                //  console.log(res)
                ElMessage({
                    message: '提交成功',
                    type: 'success',
                    plain: true,
                })
                showDialog.value = false

                emit('reflash')
            })
        }
    });
}

/**
 * 父组件调弹框显示方法
 */
const show = (row, type) => {
    // console.log(row)
    showDialog.value = true;

    queryParams.value = JSON.parse(JSON.stringify(row))
    currentType.value = type
};

onMounted(() => {

});

onBeforeUnmount(() => {

});

defineExpose({ show });
</script>